<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>博客发布</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
  <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css">
  <link rel="stylesheet" href="../../static/css/me.css">
</head>
<body>

<!--导航-->
<nav class="ui m-bg attached segment m-padded-tb-mini m-shadow-small animated fadeInDown" style="z-index: 999!important;">
  <div class="ui container">
    <div class="ui secondary stackable menu">
      <h2 class="ui teal header item">管理后台</h2>
      <a href="#" th:href="@{/admin/blogs}" class="active m-item item m-mobile-hide"><i class="home icon"></i>博客</a>
      <a href="#" th:href="@{/admin/types}" class="m-item item m-mobile-hide"><i class="idea icon"></i>分类</a>
      <a href="#" th:href="@{/admin/tags}" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
      <a href="#" th:href="@{/admin/friendlinks}" class="m-item item m-mobile-hide"><i class="pencil icon"></i>友链管理</a>
      <div class="right m-item m-mobile-hide menu">
        <div class="ui dropdown  item">
          <div class="text">
            <img class="ui avatar image" src="http://rf479zmaa.hn-bkt.clouddn.com/avatar.jpg"
                 th:src="@{${session.user.avatar}}">
            <span th:text="${session.user.nickname}">Kindnit</span>
          </div>
          <i class="dropdown icon"></i>
          <div class="menu">
            <a href="#" th:href="@{/logout}" class="item">注销</a>
          </div>
        </div>
      </div>
    </div>
  </div>
  <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
    <i class="sidebar icon"></i>
  </a>
</nav>

  <div class="ui attached pointing menu">
    <div class="ui container">
      <div class="right menu">
        <a href="#" class="teal active item">发布</a>
        <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
      </div>
    </div>
  </div>

  <!--中间内容-->
  <div  class="m-container m-padded-tb-big">
    <!--ui提供的container:提供的宽度固定，显示最好的显示效果-->
    <div class="ui container">
      <!--post:提交-->
      <form id="blog-form" action="#" method="post" th:action="${blog}==null ? @{/admin/blogs/add} : @{/admin/blogs/update}" th:object="${blog}" class="ui form">
        <input type="hidden" name="published" th:value="${blog}!=null ? ${blog.isPublished()}">
        <input type="hidden" name="id"  th:id="${blog} ==null ? randomId" th:value="${blog}!=null ? ${blog.getId()}">
        <!--required:要求必须输入，不输入显示红色-->
        <div class="required field">
          <!--左边是labeled和input结合-->
          <div class="ui left labeled input">
            <!--select在前，input在后、dropdown:选择，compact:宽度和文本一样，适应文本-->
            <div class="ui selection compact teal basic dropdown label">
              <!--默认值原创：下拉的时候选择原创-->
              <input type="hidden" value="原创" name="flag" th:value="${blog}!=null ? ${blog.getFlag()}" >
              <i class="dropdown icon"></i>
              <div class="text">原创</div>
              <div class="menu">
                <!--item：选项、data-value：选项的值-->
                <div class="item" data-value="原创">原创</div>
                <div class="item" data-value="转载">转载</div>
                <div class="item" data-value="翻译">翻译</div>
              </div>
            </div>
            <input type="text" name="title" placeholder="标题" th:value="${blog}!=null ? ${blog.getTitle()}" >
          </div>
        </div>

        <div class="required field">
          <!--style="z-index: 1 !important:代表叠放层次，放在最上层-->
          <div id="md-content" style="z-index: 1 !important;">
            <!--name="content" style="display: none引入的插件样例用法，直接复制用，在editor.md--examples--si mple.html文件-->
            <textarea placeholder="博客内容" name="content" th:text="${blog}!=null ? ${blog.getContent()}" style="display: none" ></textarea>
          </div>
        </div>


        <div class="two fields">
          <!--放分类-->
          <div class="required field">
            <!--左边是labeled和input结合-->
            <div class="ui left labeled action input">
              <!--select在前，input在后、dropdown:选择，compact:宽度和文本一样，适应文本-->
              <label class="ui compact teal basic label">分类</label>
              <!--fluid;撑满-->
              <div class="ui fluid selection dropdown">
                <!--type不为空才调用type.id-->
                <input type="hidden" name="typeId" th:value="${blog}!=null ? ${blog.getTypeId()}">
                <i class="dropdown icon"></i>
                <div class="default text">分类</div>
                <div class="menu">
                  <!--item：选项、data-value：选项的值-->
                  <div th:each="type : ${types}" th:data-value="${type.getId()}" th:text="${type.getName()}" class="item" data-value="1" >错误日志</div>
                </div>
              </div>
            </div>
          </div>
          <div class="field">
            <!--左边是labeled和input结合-->
            <div class="ui left labeled action input">
              <!--select在前，input在后、dropdown:选择，compact:宽度和文本一样，适应文本-->
              <label class="ui compact teal basic label">标签</label>
              <!--fluid;撑满、multiple search:多选+搜索-->
              <div class="ui fluid selection multiple dropdown">
                <input type="hidden" name="tagIds" th:value="${blog}!=null ? ${blog.getTagIds()}">
                <i class="dropdown icon"></i>
                <div class="default text">标签</div>
                <div class="menu">
                  <!--item：选项、data-value：选项的值-->
                  <div class="item" th:each="tag : ${tags}" th:data-value="${tag.getId()}" th:text="${tag.getName()}" data-value="1">java</div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="required field">
          <div class="ui left labeled input">
            <label class="ui teal basic label">首图</label>
            <input type="text" name="firstPicture" th:value="${blog}!=null ? ${blog.getFirstPicture()}" placeholder="首图引用地址">
          </div>
        </div>

        <div class="required field">
          <textarea name="description" th:text="${blog}!=null ? ${blog.getDescription()}"  placeholder="博客描述..." maxlength="200"></textarea>
        </div>

        <div class="inline fields">
          <div class="field">
            <!--checkbox:UI的组件-->
            <div class="ui checkbox">
              <input type="checkbox" id="recommend" name="recommend" th:checked=" ${blog}!=null ? ${blog.isRecommend()}" checked class="hidden">
              <label for="recommend">推荐</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="shareStatement" th:checked="${blog}!=null ? ${blog.isShareStatement()}" name="shareStatement" class="hidden">
              <label for="shareStatement">转载声明</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="appreciation" th:checked="${blog}!=null ? ${blog.isAppreciation()}" name="appreciation" class="hidden">
              <label for="appreciation">赞赏</label>
            </div>
          </div>
          <div class="field">
            <div class="ui checkbox">
              <input type="checkbox" id="commentabled" th:checked="${blog}!=null ? ${blog.isCommentabled()}" name="commentabled" class="hidden">
              <label for="commentabled">评论</label>
            </div>
          </div>
        </div>



        <!--将错误放在这个div里-->
        <div class="ui error message"></div>

        <div class="ui right aligned container">
          <!--window.history.go(-1):返回上一个页面-->
          <button type="button" class="ui button" onclick="window.history.go(-1)" >返回</button>
          <!--secondary：颜色显示是优先级第二；黑色-->
          <button type="button" id="save-btn" class="ui secondary button">保存</button>
          <button type="button" id="publish-btn" class="ui teal button">发布</button>
        </div>

      </form>
    </div>

  </div>

  <br>
  <br>
  <!--底部footer-->
  <footer th:replace="_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
      <div class="ui inverted divided stackable grid">
        <div class="three wide column">
          <div class="ui inverted link list">
            <div class="item">
              <img src="../../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px">
            </div>
          </div>
        </div>
        <div class="three wide column">
          <h4 class="ui inverted header m-text-thin m-text-spaced " >最新博客</h4>
          <div class="ui inverted link list">
            <a href="#" class="item m-text-thin">用户故事（User Story）</a>
            <a href="#" class="item m-text-thin">用户故事（User Story）</a>
            <a href="#" class="item m-text-thin">用户故事（User Story）</a>
          </div>
        </div>
        <div class="three wide column">
          <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
          <div class="ui inverted link list">
            <a href="#" class="item m-text-thin">Email：983022332@qq.com</a>
            <a href="#" class="item m-text-thin">QQ：983022332</a>
          </div>
        </div>
        <div class="seven wide column">
          <h4 class="ui inverted header m-text-thin m-text-spaced ">Blog</h4>
          <p class="m-text-thin m-text-spaced m-opacity-mini">这是我的个人博客、会分享关于编程、写作、思考相关的任何内容，希望可以给来到这儿的人有所帮助...</p>
        </div>
      </div>
      <div class="ui inverted section divider"></div>
      <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2022 - 2023 Kindnit Designed by Kindnit</p>
    </div>

  </footer>

  <!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
  <script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
  <!--/*/</th:block>/*/-->
  <!--引入md插件JS-->
  <script src="../../static/lib/editormd/editormd.min.js"></script>


  <script>

    //初始化Markdown编辑器
    var contentEditor;
    $(function() {
      contentEditor = editormd("md-content", {
        width   : "100%",
        height  : 640,
        syncScrolling : "single",
        // path    : "../../static/lib/editormd/lib/"
        path    : "/lib/editormd/lib/"
      });
    });

    //<!--jQuery获取这个元素-->
    $('.menu.toggle').click(function () {//toggleClass开关一样的样式
      $('.m-item').toggleClass('m-mobile-hide');//m-item:获取那几个列表，点击的时候处理m-mobile-hide
    });
    //<!--jQuery:按钮之后触发，执行JS组件-->
    // $('#payButton').popup({         //获得按钮、.popup:没有为什么，调用组件
    //     popup : $('.payQR.popup'),  //拿到二维码对象，定位到这个元素
    //     //on : 'click',               //点击的时候触发
    //     position: 'bottom center'   //position位置：在中下的位置触发
    // });
    $('.ui.dropdown').dropdown({        //鼠标放上去就会出现下拉
      on : 'hover'                    //默认是点击，hover鼠标放上去就出来
    });

    //点击save动态处理
    $('#save-btn').click(function () {
      $('[name="published"]').val(false);
      $('#randomId').val(Number(createRandomId()));
      $('#blog-form').submit();
    });

    function createRandomId() {
      return (new Date()).getTime();
    }

    $('#publish-btn').click(function () {
      $('[name="published"]').val(true);
      $('#randomId').val(Number(createRandomId()));
      $('#blog-form').submit();
    });

    $('.ui.form').form({
      fields : {
        title : {
          identifier: 'title',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客标题'
          }]
        },
        content : {
          identifier: 'content',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客内容'
          }]
        },
        typeId : {
          identifier: 'typeId',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客分类'
          }]
        },
        firstPicture : {
          identifier: 'firstPicture',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客首图'
          }]
        },
        description : {
          identifier: 'description',
          rules: [{
            type : 'empty',
            prompt: '标题：请输入博客描述'
          }]
        }
      }
    });
  </script>
</body>
</html>